<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/19
 * Time: 11:04
 */

namespace app\http\middleware;


use think\facade\Cache;

class CheckToken
{
    public function handle($request, \Closure $next)
    {
        $token = $request->param("token");

        if (empty($token)) {
            return json(["code" => 0 , "message" => "缺少必要字段token"]);
        }

        if (Cache::get("token") !== $token) {
            return json(["code" => 0 , "message" => "错误token"]);
        }

        return $next($request);
    }
}